package com.yiren.dbaa.util;

/**
 * Created by WANGRONGXIANG
 * on 2022/4/14
 * Describe 轨迹绘制精度像素工具类
 */
public class AccuracyPixelUtil {

    //缩放比例
    public final static int Accuracy_M2 = 6;
    public final static int Accuracy_M4 = 7;
    public final static int Accuracy_M7 = 8;
    public final static int Accuracy_M10 = 9;
    public final static int Accuracy_M15 = 10;
    public final static int Accuracy_M20 = 11;
    public final static int Accuracy_M30 = 12;
    public final static int Unit_Pixel = 100;

    /**
     * 根据精度获取缩放比例尺
     */
    public static float getAccuracyScale(int accuracy) {
        switch (accuracy) {
            case Accuracy_M2:
                return 0.5f;
            case Accuracy_M4:
                return 0.25f;
            case Accuracy_M7:
                return 0.1428f;
            case Accuracy_M10:
                return 0.1f;
            case Accuracy_M15:
                return 0.075f;
            case Accuracy_M20:
                return 0.05f;
            case Accuracy_M30:
                return 0.03333f;
            default:
                return 0.5f;
        }
    }

    /**
     * 获取精度对应的比例尺
     * @param accuracy
     * @return
     */
    public static String getAccuracyText(int accuracy) {
        switch (accuracy) {
            case Accuracy_M2:
                return "2米";
            case Accuracy_M4:
                return "4米";
            case Accuracy_M7:
                return "7米";
            case Accuracy_M10:
                return "10米";
            case Accuracy_M15:
                return "15米";
            case Accuracy_M20:
                return "20米";
            case Accuracy_M30:
                return "30米";
            default:
                return "未知";
        }
    }

    /**
     * x方向长度转换为像素
     */
    public static float xDistanceToPixel(float x, int originX, int accuracy) {
        return originX + distanceToPixel(x, accuracy);
    }

    /**
     * y方向长度转换为像素
     */
    public static float yDistanceToPixel(float y, int originY, int accuracy) {
        return originY - distanceToPixel(y, accuracy);
    }

    /**
     * 长度转换为像素
     */
    public static int distanceToPixel(float distance, int accuracy) {
        float scale = getAccuracyScale(accuracy);
        return (int) (distance * scale * Unit_Pixel);
    }

    /**
     * 像素转换为距离
     * @param pixel
     * @param accuracy
     * @return
     */
    public static float pixelToDistance(int pixel, int accuracy) {
        float scale = AccuracyPixelUtil.getAccuracyScale(accuracy);
        return ((float) pixel) / (scale * Unit_Pixel);
    }

}
